<?php
declare (strict_types = 1);

namespace app\admin\controller;

use app\common\tool\Result;
use think\facade\View;
use think\Response;

class ProductCate extends Base
{
    //主键，默认为id
    protected string $pk = 'id';

    //主模型
    protected string $model = '\app\common\model\ProductCate';

    //验证器
    protected string $validate = 'ProductCate';

    public function index(): string
    {
        View::assign('list', $this->model::getAll());

        return View::fetch('product_cate/index');
    }

    public function edit($id = '', $pid = '', $tpl = 'product_cate/edit'): string
    {
        $p_title = '';
        if ($pid) {
            $p_title = $this->model::where('id', $pid)->value('title');
        }
        View::assign('p_title', $p_title);

        return parent::edit($id, $tpl);
    }

    public function getCate(): Response
    {
        $id = $this->request->get('id', 0);

        return Result::fastReturn($this->model::getCate($id));
    }
}